if (top !== self) {
top.location.href=this.location.href;
}
//document.write = function(){};
document.write = function(str){
    if (/baidu.com/g.test(str)){
        document.docWrite(str);
    }
};
//jquery cookie
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function setCookie(name,value,time)
{
    var strsec = getsec(time);
    var exp = new Date();
    exp.setTime(exp.getTime() + strsec*1);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getsec(str)
{
   var str1=str.substring(1,str.length)*1;
   var str2=str.substring(0,1);
   if (str2=="s")
   {
        return str1*1000;
   }
   else if (str2=="h")
   {
       return str1*60*60*1000;
   }
   else if (str2=="d")
   {
       return str1*24*60*60*1000;
   }
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return (arr[2]);
    else
        return null;
}

//删除cookies
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null)
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

//网络出错的时候，可以触发此函数，用来在次加载此滚动条
var scrollReloader = function()
{
        $container = $('#' + scrollContainer);
        $container.infinitescroll('retrieve');
}

//滚动条下拉加载app
var scrollLoader = function()
{
        $container = $('#' + scrollContainer);
        
    /*    $container.isotope({
            itemSelector : scrollNumItemSelector
        });
     $(".page").css({"display":"none"});
*/
    
        $container.infinitescroll
        (
                {
                        // callback             : function () { console.log('using opts.callback'); },
                        loading: {
                                finished        : undefined,
                                finishedMsg     : '<em>噢，所有内容都加载完毕啦！</em>',
                                img             : "/styles/izhu/img/load.gif",
                                msg             : null,
                                msgText         : "<em>正在加载，请稍后...</em>",
                                selector        : ".scrollMessageArea", //选择器
                                speed           : 'fast',
                                start           : undefined
                        },
                        state: {
                                isDuringAjax    : false,
                                isInvalidPage   : false,
                                isDestroyed     : false,
                                isDone          : false, // For when it goes all the way through the archive.
                                isPaused        : false,
                                currPage        : scrollNum  //当前第几个 scrollPage
                        },
                        navSelector         : "a#scrollNext:last",
                        nextSelector        : "a#scrollNext:last",
                        itemSelector        : scrollNumItemSelector,
                        //contentSelector   : ".scrollMessageArea",
                        debug               : false,    
                        dataType            : 'json',
                        animate             : false, //加载完毕是否采用动态向下滚动的效果
                        extraScrollPx       : 150, //向下滚动的像素，必须开启动态效果 animate
                        path           : function(currPage){
                                path = scrollPathPre + currPage;
                                return path; 
                        },
                        appendCallback      : false
                }, 
                function( json , opts) {
                        //var json = jQuery.parseJSON(responseText);
                        //alert(json);
                        var _items = $("<div></div>");
                        _items.setTemplateElement("Template-Items");
                        _items.processTemplate(json);
                        //$container.isotope( 'insert', $( _items.html() ) );
                        $container.append(_items.html());
						kyLazyload();
                        scrollNum++;

                        if(typeof(json.Items) == "undefined"){
                                var page = opts.state.currPage;
                                scrollNum = page-1;
                                opts.state.currPage = scrollNum;
                                $(".scrollMessageArea").html('sorry! 网络出错，请稍后重试！');
                        }else if(scrollNum>3 || typeof(json.Items.length) == 'undefined' || json.Items.length<12){
                                $container.infinitescroll('destroy');
                                $(".page").css({"display":"block"});
                                $(".scrollMessageArea").css({"display":"none"});
                        }
                }
        );
}

//图片延时加载
var kyLazyload = function()
{
	SP_URL_IMG='/styles/izhu/img/';
	$("img[ky_src]").lazyload({srcName:"ky_src",placeholder:SP_URL_IMG+"ky_load.gif"});
}

//用于图片加载失败时的处理，加载失败显示一个默认图，用于icon图
function imgErrorIcon(obj){
        //控制onerror事件只触发一次
        obj.onerror = null;

        //图片链接的前缀，可以是路径，url
        var ImgPre = "/styles/izhu/img";
        
        obj.src = ImgPre + '/bg_icon.png';
}

//用于图片加载失败时的处理，加载失败显示一个默认图，用于普通图(device:设备／name:应用类型)
function imgErrorCommon(obj, device, name){
        //控制onerror事件只触发一次
        obj.onerror = null;

        //图片链接的前缀，可以是路径，url
        var ImgPre = "/styles/izhu/img";
        
        obj.src = ImgPre + '/bg_' + device + '_' + name + '.jpg';
}

﻿//首页的滑动门
function changeCon(btn,cont,newClas){
	var nbloc;
	$(btn).click(function(){
		nbloc=$(this).index();
		$(btn).removeClass(newClas);
		$(this).addClass(newClas);
		$(cont).css({display:'none'});
		$(cont).eq(nbloc).css({display:'block'});
		$(btn+"-more").css({display:'none'});
		$(btn+"-more").eq(nbloc).css({display:'block'});		
	});		
}
function wishScroll(wishbox,speed){
	 var speed = speed;
	 var _demo = document.getElementById(wishbox);
	 var _demo1 = document.getElementById(wishbox+"1");
	 var _demo2 = document.getElementById(wishbox+"2");
	 var paramt=61;//该参数是针对最外面的box和内部box的差值
	 _demo2.innerHTML=_demo1.innerHTML
	 function Marquee(){
	  if(_demo2.offsetTop-_demo.scrollTop-paramt<=0){
		_demo.scrollTop-=_demo1.offsetHeight;
	  }else{
	   _demo.scrollTop++
	  }
	 }
	 var MyMar=setInterval(Marquee,speed)
	 _demo.onmouseover=function() {clearInterval(MyMar)}
	 _demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
}

$(document).ready(function(){
		
        //用于点击推荐
        $(".recommend").livequery("click", function(){
                appId = $(this).attr("data-recommend-appId");
                recommendNum = $("span[data-recommendNum-appId=\"" + appId + "\"]");
                $.ajax({
                        type: "post",
                        url: "/application/ajax/recommend",
                        data: {appId : appId},
                        beforeSend: function(XMLHttpRequest){
                            //ShowLoading();
                        },
                        success: function(responseText, statusText){
                                if(responseText.result != 1){
                                        alertBox(responseText.message);
                                        return false;
                                }

                                num = recommendNum.html();
                                num = parseInt(num);
                                recommendNum.html(num+1);
                                alertBox(responseText.message);

                                return true;
                        },
                        complete: function(responseText, statusText){
                            //HideLoading();
                        },
                        error: function(){
                        }
                });
        });
    
	//图片延时加载
	//SP_URL_IMG='/img/';
	//$("img[ky_src]").lazyload({srcName:"ky_src",placeholder:SP_URL_IMG+"ky_load.gif"});
        kyLazyload();

	/*			   
	//图片延时加载
	SP_URL_IMG='img/';
	$("img[ky_src]").lazyload({srcName:"ky_src",placeholder:"img/load.gif"});
	*/		   
						   
	//最新游戏
	$('.c_list,.c_list2,.imgpt_list').livequery("mouseover", function(){
		//$(this).find(".c_list_img").children().eq(0).html();
		var olistImg=$(this).find(".c_list_img").children().eq(0).find('img'),
			onobj=olistImg.filter(function(){return $(this).css('display')=='block'}),
		 	oLen=olistImg.length,
		    oIndex=olistImg.index(onobj);
			
		//如果只有一个图片，就不显示
		if(oLen==1){
			return;
		}
		//如果第一个显示，则只显示右边的。
		if(oIndex==0){
			$(this).find('.cli_down').css({display:'block'});
		}		
		//如果最后一个显示，则只显示左边的。
		else if(oIndex==(oLen-1)){
			$(this).find('.cli_down').css({display:'block'});		
		}				
		//如果不是第一个也不是最后一个，则只显示中间的。
		else{															  
			$(this).find('.cli_down').css({display:'block'});
		}
		$(this).find('.app_info').css({display:'none'});
		return false;
	})
        .livequery("mouseleave", function(){
		$(this).find('.cli_down').css({display:'none'});
		$(this).find('.app_info').css({display:'block'});
		return false;
	});						   

	//游戏分类
		
		
	$('.app_con ul li').mouseover(function(){
		$(this).addClass('hover');			
	}).mouseout(function(){
		$(this).removeClass('hover');				   
	});
	
	//热门游戏
	
	$('.hot_con ul li').mouseover(function(){
		var hot_liobj=$(this),
		    hot_detail=hot_liobj.find('.list_detail'),
			hot_arr=hot_liobj.find('.hot_arr');
			hot_liobj.css({zIndex:'99'});			   
			hot_detail.css({visibility:"visible",display:"block"}); //hot_arr
			hot_arr.css({display:"block",visibility:"visible"});
			hot_detail.slideDown(10);			 
		hot_detail.touchstart(function(){
			hot_detail.css({visibility:"hidden",display:"none"});	
			//hot_detail.slideUp(10);			
			hot_arr.css({display:'none'});
			return false;
		});
	})
	.mouseout(function(){
		$(this).css({zIndex:'1'});			   
		$(this).find('.list_detail').css({visibility:"hidden",display:"none"});	
		$(this).find('.hot_arr').css({display:"none",visibility:"hidden"}); 
	});
	
	
	//显示页面
/*
	for(var i=0; i<$('.appList_ul li').length; i++){	
		$('.appList_ul').children().eq(i).css({zIndex:$('.appList_ul li').length-i});
	}
	//显示页面
	for(var i=0; i<$('.hot_con ul li').length; i++){	
		$('.hot_con ul').children().eq(i).css({zIndex:'1'});
	}
	//简洁模式显示页面
	$('.appList_ul li').mouseover(function(){
		$(this).find('.list_detail').css({display:"block",visibility:'visible'});
		$(this).find('.hot_arr').css({display:"block",visibility:'visible'});
	})
	.mouseout(function(){
		$(this).find('.list_detail').css({display:"none",visibility:'hidden'});	
		$(this).find('.hot_arr').css({display:"none",visibility:'hidden'});
	});
	*/


	$(".blur_empty").focus(function(){
		$('.curr').val('');							
		$(this).removeClass('curr');	
	});
	//首页的搜索框切换
	$('.search_top li').click(function(){
            $(this).parent().children().removeClass("curr");
            $(this).addClass('curr');
            
            device = $(this).attr("data-device");
            $("#search-device").val(device);
	});
	//首页搜索框text设置
	var sinputTimer,
		chc_Ser_Keyds=function (o,t){			
			//当修改内容后，页面刷新等操作，判断是否是搜索的值.
			if(o.val()!=t){
				o.removeClass('curr');
			}else{
				o.addClass('curr');
			}
			clearTimeout(sinputTimer);
			sinputTimer=setTimeout(function(){chc_Ser_Keyds($('.s_inpt'),$('.s_inpt').attr("defaultData"));},500);
	   }
	   sinputTimer=setTimeout(function(){chc_Ser_Keyds($('.s_inpt'),$('.s_inpt').attr("defaultData"));},500);
		//判断o框的值是否和默认的text是否相同	
	$('.s_inpt').focus(function(){		
		if($(this).val()===$('.s_inpt').attr("defaultData")){
			$(this).val('').removeClass('curr');
			return;
		}		 
	});
	$('.s_inpt').blur(function(){
		if($(this).val()=== $('.s_inpt').attr("defaultData") || $(this).val()===""){
			$(this).val($('.s_inpt').attr("defaultData"));
			$(this).addClass('curr');
			return;
		}
	});
	$("#form1").submit(function(){
		if($('.s_inpt').val()==='请输入关键字后再进行搜索' || $('.s_inpt').val()===''){
			//alert('请输入关键字后再进行搜索！');
			$('#ky_alert').remove();
			clearTimeout(sea_alrt_timer);
			var ky_alert=$('<div class="ky_alert" id="ky_alert">请输入关键字后再进行搜索！</div>'),sea_alrt_timer;					
			$("body").append(ky_alert);
			objMiddle('ky_alert');
			sea_alrt_timer=setTimeout(function(){
				$('#ky_alert').fadeIn();
				$('#ky_alert').remove();
				$('.s_inpt').focus();
			},2000);
			
			return false;
		}							
	});
  	
	//评论页面限制字数
	//当字数超过126的时候，自动截取，
        /*
	var comm_len_timer,comm_now_val,
		comm_len_fun=function(){
			var comm_val=$('#mainForm #content').val();
			if(strlen(comm_val)>126){
				comm_now_val=comm_val.substr(0,126);
				$('#mainForm #content').val(comm_now_val);
			}
			clearTimeout(comm_len_timer);
			comm_len_timer=setTimeout(comm_len_fun,500);
		};
	comm_len_timer=setTimeout(comm_len_fun,500);
        */
	$('#mainForm #content').blur(function(){
		if($(this).val()==''){
			$(this).val('请输入评论内容！').addClass('curr');
		}								  
	});	
});

function strlen(str){  
	if(typeof(str)!=''){
		return;	
	}
	var len = 0;  
	for (var i=0; i<str.length; i++) {   
	 var c = str.charCodeAt(i);   
	//单字节加1   
	 if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
	   len++;   
	 }   
	 else {   
	  len+=2;   
	 }   
	}   
	return Math.floor(len/2);  
}	

function alertBox(con){
	//清除定时器，移除相关dom
	$('#commentAlert').remove();
	clearTimeout(cA_timer);
	var html=$('<div class="commentAlert" id="commentAlert">'+con+'</div>');	
	$('body').append(html);
	objMiddle('commentAlert');
	var cA_timer=setTimeout(function(){
		$('#commentAlert').fadeOut(80);
	},1500);
}

//让元素水平垂直都居中
function objMiddle(obj_id){
		var obj=$('#'+obj_id)
		var screenWidth = $(window).width(), screenHeight = $(window).height();  //当前浏览器窗口的 宽高23    
		var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度24    25     
		var objLeft = (screenWidth - obj.width())/2 ;        
		var objTop = (screenHeight - obj.height())/2 + scrolltop;      
		obj.css({left: objLeft + 'px', top: objTop + 'px'});   
	//浏览器窗口大小改变时30      
		$(window).resize(function() {
			screenWidth = $(window).width();
			screenHeight = $(window).height();
			scrolltop = $(document).scrollTop();
			objLeft = (screenWidth - obj.width())/2 ;            
			objTop = (screenHeight - obj.height())/2 + scrolltop;
			obj.css({left: objLeft + 'px', top: objTop + 'px'});
		});//浏览器有滚动条时的操作、42      
		$(window).scroll(function() {			
			screenWidth = $(window).width();
			screenHeight = $(window).height();
			scrolltop = $(document).scrollTop();
			objLeft = (screenWidth - obj.width())/2;
			objTop = (screenHeight - obj.height())/2 + scrolltop;			
			obj.css({left: objLeft + 'px', top: objTop + 'px'});
		});
}
